package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.Food;
import com.neuedu.yyzx.service.IFoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 膳食信息 前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//food")
public class FoodController {
    @Autowired
    IFoodService foodService;

    @RequestMapping("/list")
    CommonResult list(Page page, Food food){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        if(food!= null && StringUtils.isNotEmpty(food.getFoodName())){
            queryWrapper.like("food_name",food.getFoodName());
        }
        return CommonResult.success(foodService.page(page,queryWrapper));
    }

    @RequestMapping("/add")
    CommonResult add(Food food){
        return CommonResult.success(foodService.saveOrUpdate(food));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer id){

        return CommonResult.success(foodService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del (Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("id",id);

        return CommonResult.success(foodService.update(updateWrapper));
    }

    //周一
    @RequestMapping("/breakfast")
    CommonResult food(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",1);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch")
    CommonResult lfood(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",1);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner")
    CommonResult dfood(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",1);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周二
    @RequestMapping("/breakfast2")
    CommonResult food2(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",2);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch2")
    CommonResult lfood2(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",2);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner2")
    CommonResult dfood2(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",2);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周三
    @RequestMapping("/breakfast3")
    CommonResult food3(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",3);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch3")
    CommonResult lfood3(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",3);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner3")
    CommonResult dfood3(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",3);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周四
    @RequestMapping("/breakfast4")
    CommonResult food4(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",4);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch4")
    CommonResult lfood4(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",4);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner4")
    CommonResult dfood4(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",4);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周五
    @RequestMapping("/breakfast5")
    CommonResult food5(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",5);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch5")
    CommonResult lfood5(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",5);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner5")
    CommonResult dfood5(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",5);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周六
    @RequestMapping("/breakfast6")
    CommonResult food6(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",6);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch6")
    CommonResult lfood6(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",6);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner6")
    CommonResult dfood6(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",6);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    //周日
    @RequestMapping("/breakfast7")
    CommonResult food7(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",1);
        queryWrapper.eq("supply_date",7);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }
    @RequestMapping("/lunch7")
    CommonResult lfood7(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",2);
        queryWrapper.eq("supply_date",7);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }

    @RequestMapping("/dinner7")
    CommonResult dfood7(){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("supply_type",3);
        queryWrapper.eq("supply_date",7);
        queryWrapper.eq("is_deleted",0);
        return CommonResult.success(foodService.list(queryWrapper));
    }


}
